<template>
  <div>
    <!-- 面包屑区域 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item> 订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片区域 -->
    <el-card>
      <el-row>
        <el-col :span="8">
          <el-input
            placeholder="请输入内容"
            v-model="queryInfo.query"
            clearable
            @clear= "getOrderlist">
            <el-button
              slot="append"
              class="el-icon-search"
              @click = "getOrderlist"
            ></el-button>
          </el-input>
        </el-col>
      </el-row>
      <!-- 表格区域 -->
      <el-table :data="OrdertableData" stripe border style="width: 100%">
        <el-table-column type="index" label="#"> </el-table-column>
        <el-table-column prop="order_number" label="订单编号">
        </el-table-column>
        <el-table-column prop="order_price" label="订单价格"> </el-table-column>
        <el-table-column prop="pay_status" label="是否付款">
          <template slot-scope="scope">
            <el-tag type="success" v-if="scope.row.pay_status === '1'"
              >已付款</el-tag
            >
            <el-tag type="danger" v-else>未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货">
          <template slot-scope="scope">
            {{ scope.row.is_send }}
          </template>
        </el-table-column>
        <el-table-column prop="create_time" label="下单时间">
          <template slot-scope="scope">
            {{ scope.row.create_time | dateFormat }}
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <!-- {{ scope.row }} -->
            <el-button
              size="mini"
              type="primary"
              icon="el-icon-edit"
              @click="editOrderlocation"
            ></el-button>
            <el-button
              size="mini"
              type="success"
              icon="el-icon-location"
              @click="showOrderlocation(scope.row.user_id)"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="this.queryInfo.pagenum"
        :page-sizes="[5, 10, 15]"
        :page-size="this.queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-card>
    <!-- 地图时间轴 -->
    <el-dialog title="物流进度" :visible.sync="dialoglocationVisible">
      <el-timeline>
        <el-timeline-item
          v-for="(activity, index) in kuaidi"
          :key="index"
          :timestamp="activity.time"
        >
          {{ activity.context }}
        </el-timeline-item>
      </el-timeline>
    </el-dialog>
    <!-- 修改对话框 -->
    <el-dialog title="修改信息" :visible.sync="dialogEditVisible">
      <el-form
        ref="editOrderFormRef"
        :model="editOrderForm"
        label-width="85px"
        :rules="editOrderFormRules"
      >
        <el-form-item label="省市区/县" prop="address1">
          <el-cascader
            v-model="selectkeys"
            :options="citydata"
            :props="editOrderProps"
            @change="handleChange"
            clearable
          ></el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" prop="address2">
          <el-input></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogEditVisible = false">取 消</el-button>
        <el-button type="primary" @click="submitEditForm">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import axios from "axios";
import kuaidi from "./kuaidi";
import citydata from "./citydata";
export default {
  data() {
    return {
      queryInfo: {
        query: "",
        pagenum: 1,
        pagesize: 2,
      },
      //订单数据表
      OrdertableData: [],
      //总页数
      total: 0,
      dialoglocationVisible: false,
      //如果属性名和属性值相等，可以简写
      kuaidi,
      citydata,
      dialogEditVisible: false,
      editOrderForm: {},
      editOrderProps: {
        expandTrigger: "click",
      },
      selectkeys: [],
      editOrderFormRules: {
        address1: [
          { required: true, message: "请选择省市区县", trigger: "blur" },
        ],
        address2: [
          { required: true, message: "请填写详细地址", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    this.getOrderlist();
  },
  methods: {
    // 获取订单列表
    getOrderlist() {
      axios
        .get("orders", {
          params: this.queryInfo
        })
        .then(({ data: res }) => {
          console.log(res);
          this.OrdertableData = res.data.goods;
          this.total = res.data.total;
        })
        .catch((error) => error);
    },
    // 更改每页条数事件
    handleSizeChange(newsize) {
      this.queryInfo.pagesize = newsize;
      this.getOrderlist();
    },
    handleCurrentChange(newnum) {
      this.queryInfo.pagenum = newnum;
      this.getOrderlist();
    },
    // 打开时间轴
    showOrderlocation() {
      this.dialoglocationVisible = true;
      //   console.log(this.kuaidi);
    },
    // 修改级联选择器
    editOrderlocation() {
      //   console.log(this.citydata);
      this.dialogEditVisible = true;
    },
    // 更改级联选择器的事件
    handleChange() {
      console.log(this.selectkeys);
    },

    submitEditForm() {
      this.$refs.editOrderFormRef.validate((valid) => {
        if (!valid) return;
        dialogEditVisible = false;
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.el-table {
  font-size: 12px;
}
.el-cascader {
  width: 100%;
}
</style>